package com.mifengkong.frwidget.webview;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.DownloadListener;
import android.webkit.URLUtil;

/**
 * Created by jiangyongxing on 2017/5/5.
 * 描述：给webview使用的下载监听
 */
public class MyWebViewDownLoadListener implements DownloadListener {

    private Context mContext;

    public MyWebViewDownLoadListener(Context context) {
        this.mContext = context;
    }

    @Override
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        url = url.trim();
        if (URLUtil.isValidUrl(url)) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            mContext.startActivity(intent);
        }
    }
}
